﻿-- =============================================
-- Author:		Wolf Gilbert
-- Create date: 7/16/06
-- Description:	
-- =============================================
CREATE PROCEDURE [ServiceEngine].[UpdateEndpoint]
	@Name nvarchar(400),
	@BindingID uniqueidentifier,
	@PolicyID uniqueidentifier,
	@NamespaceURI ntext = null,
	@TestCallsAccepted bit = null,
	@AutoOperationPubUpdate bit = null,
	@AutoOperationActivationUpdate bit = null,
	@Description ntext = null,
	@Configuration xml = null,
	@ServiceName nvarchar(400) = null,
	@Port int = 0,
	@ID uniqueidentifier
AS
BEGIN
	DECLARE @ErrorMessage NVARCHAR(4000);
	DECLARE @ErrorSeverity INT;
	DECLARE @ErrorState INT;
	SET NOCOUNT ON;

	BEGIN TRY
		BEGIN TRANSACTION

		UPDATE	ServiceEngine.Endpoints 
		SET		BindingID = @BindingID,
				NamespaceURI = @NamespaceURI,
				TestCallsAccepted = @TestCallsAccepted,
				AutoOperationPubUpdate = @AutoOperationPubUpdate,
				AutoOperationActivationUpdate = @AutoOperationActivationUpdate,
				Configuration = @Configuration,
				ServiceName = @ServiceName,	
				Port = @Port,	
				PolicyID = @PolicyID
		WHERE	EndpointID = @ID

		UPDATE	ServiceEngine.Names
		SET		EntityName = @Name,
				EntityDescription = @Description
		WHERE	EntityID = @ID and EntityTypeID = 2

		COMMIT TRANSACTION
	END TRY
	BEGIN CATCH
		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;

		RAISERROR (@ErrorMessage, 
				   @ErrorSeverity,
				   1);
	END CATCH

END


